Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(publish-to-npm): Download and extract build as single artifact at the correct path (fixes #48). #49

Merged
merged 3 commits into from
Dec 31, 2024

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented Dec 29, 2024

Related: #48

Description

  1. ci(publish-to-npm): Fix incorrect artifact download path.

Validation performed

  1. With this debug workflow file: https://github.com/junhaoliao/clp-ffi-js/actions/runs/12554958088/workflow , ls -l dist in the debug job showed all the artifacts: https://github.com/junhaoliao/clp-ffi-js/actions/runs/12554958088/job/35004441486

Summary by CodeRabbit

  • Chores
    • Updated GitHub Actions workflow for npm publishing.
    • Improved artifact management during build and publish processes.
    • Enhanced workflow reliability with explicit artifact handling and error conditions.
    • Introduced a new environment variable for unique artifact naming.

Copy link

coderabbitai bot commented Dec 29, 2024

Walkthrough

The pull request modifies the GitHub Actions workflow for npm publishing in .github/workflows/publish-to-npm.yml. It introduces a new environment variable, G_CLP_FFI_JS_DIST_ARTIFACT_NAME, which incorporates the GitHub SHA for unique artifact identification. The artifact upload and download steps in the build and publish-to-npm jobs have been updated to use this environment variable instead of hardcoded values, enhancing the flexibility of artifact naming while maintaining the overall workflow structure.

Changes

File Change Summary
.github/workflows/publish-to-npm.yml - Added environment variable G_CLP_FFI_JS_DIST_ARTIFACT_NAME in publish-to-npm job
- Updated artifact upload configuration in build job to use the new environment variable
- Updated artifact download configuration in publish-to-npm job to use the new environment variable

Possibly Related PRs

  • ci: Add GH workflow for publishing to npm. #43: The changes in this PR also involve the GitHub Actions workflow for publishing to npm, specifically focusing on the build and publish jobs, which are directly related to the modifications made in the main PR regarding artifact naming and workflow configuration.

Suggested Reviewers

  • kirkrodrigues

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@junhaoliao junhaoliao changed the title ci(publish-to-npm): Fix incorrect artifact download path. ci(publish-to-npm): Fix incorrect artifact download path in GH workflow. Dec 29, 2024
@junhaoliao junhaoliao marked this pull request as ready for review December 29, 2024 23:26
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/publish-to-npm.yml (1)

37-39: Consider adding post-download verification.

While the artifact download configuration matches the upload settings, consider adding these reliability improvements:

Add a verification step after the download:

 - uses: "actions/download-artifact@v4"
   with:
     name: "dist"
     path: "dist/"
+- name: "Verify downloaded artifacts"
+  run: |
+    ls -la dist/
+    if [ ! -d "dist" ] || [ -z "$(ls -A dist/)" ]; then
+      echo "Error: dist directory is empty or missing"
+      exit 1
+    fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 225414a and 599c889.

📒 Files selected for processing (1)
  • .github/workflows/publish-to-npm.yml (2 hunks)
🔇 Additional comments (1)
.github/workflows/publish-to-npm.yml (1)

26-29: LGTM! Verify the artifact path format.

The artifact upload configuration looks good with explicit naming and error handling. The 1-day retention period is appropriate for CI artifacts.

Let's verify the path format and presence of the dist directory:

✅ Verification successful

Let me check the actual content of these files to understand how the dist directory is used.


The artifact path format "dist/" is correct and properly aligned with the project structure

The path format "dist/" in the artifact upload configuration is verified to be correct because:

  • The package.json correctly references the dist directory for npm package files and exports
  • The Taskfile.yml defines G_DIST_DIR variable that's used in the build process
  • The workflow shows a complete build-and-publish pipeline where:
    • task package generates the build artifacts
    • The artifacts are uploaded from "dist/"
    • The same path is used for downloading in the publish job
    • The path aligns with npm publish expectations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the dist directory path and its usage in the codebase

# Check if dist is mentioned in any task definitions or build scripts
rg -l "dist" package.json Taskfile.yml 2>/dev/null || echo "No dist references found in build files"

# Look for any existing dist directory patterns
fd -t d "dist$" || echo "No dist directory found"

Length of output: 82


Script:

#!/bin/bash
# Check the content of package.json and Taskfile.yml for dist-related configurations
echo "=== package.json content ==="
rg "dist" package.json -C 2

echo -e "\n=== Taskfile.yml content ==="
rg "dist" Taskfile.yml -C 2

# Check the workflow file for build steps
echo -e "\n=== Workflow file content ==="
cat .github/workflows/publish-to-npm.yml

Length of output: 1929

@junhaoliao
Copy link
Member Author

Alternatively, this config would also work though it is less straight forward:

      - name: "Upload build artifacts"
        uses: "actions/upload-artifact@v4"
        with:
          # HERE the artifacts in "dist/" are uploaded with name "artifact" (the default value of "name")
          path: "dist/"
          if-no-files-found: "error"
          retention-days: 1

  publish-to-npm:
    needs: ["build"]
    runs-on: "ubuntu-latest"
    steps:
      - uses: "actions/checkout@v4"
      - uses: "actions/download-artifact@v4"
        with:
          # HERE we ask the action to place all artifacts into the destination path
          merge-multiple: true
          # HERE we download the artifacts into "dist/" instead of "artifact/"
          path: "dist/"

kirkrodrigues
kirkrodrigues previously approved these changes Dec 30, 2024
Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One optional comment otherwise lgtm.

For the PR title, how about:

ci(publish-to-npm): Download and extract build as single artifact at the correct path (fixes #48).

@@ -23,6 +23,7 @@ jobs:
- name: "Upload build artifacts"
uses: "actions/upload-artifact@v4"
with:
name: "dist"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is optional, but do you want to call it something more readable like clp-ffi-js or clp-ffi-js-dist so that it's obvious when downloaded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean where a developer downloads the artifacts from the job's Summary page, sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

@junhaoliao junhaoliao changed the title ci(publish-to-npm): Fix incorrect artifact download path in GH workflow. ci(publish-to-npm): Download and extract build as single artifact at the correct path (fixes #48). Dec 31, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/publish-to-npm.yml (1)

40-42: Consider adding explicit error handling for artifact download

While the configuration is correct, consider adding explicit error handling to ensure the workflow fails gracefully if the artifact download fails.

Add the following configuration:

  with:
    name: "${{env.G_CLP_FFI_JS_DIST_ARTIFACT_NAME}}"
    path: "dist/"
+   fail-on-error: true
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 599c889 and 3973934.

📒 Files selected for processing (1)
  • .github/workflows/publish-to-npm.yml (3 hunks)
🔇 Additional comments (2)
.github/workflows/publish-to-npm.yml (2)

29-32: LGTM! Robust artifact upload configuration

The artifact upload configuration includes all necessary safeguards:

  • Proper error handling with if-no-files-found: "error"
  • Appropriate retention period for CI/CD context
  • Correct path specification

8-10: LGTM! Environment variable follows naming best practices

The environment variable definition is well-structured:

  • Uses a descriptive prefix "clp-ffi-js-dist" for clarity
  • Incorporates GitHub SHA for uniqueness
  • Follows the suggestion from previous reviews for better readability

Let's verify the naming convention across the workflow:

✅ Verification successful

Let me verify the artifact naming usage in more detail:


Artifact naming convention is consistently implemented

The environment variable G_CLP_FFI_JS_DIST_ARTIFACT_NAME is properly referenced throughout the workflow:

  • Defined at the workflow level for global accessibility
  • Consistently used in both upload and download artifact steps
  • Maintains uniqueness with SHA while keeping the name readable
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistent artifact naming pattern across the workflow
# Expected: Only references to the new environment variable for artifact names

rg -i 'name:.*artifact' .github/workflows/publish-to-npm.yml

Length of output: 219


Script:

#!/bin/bash
# Check all references to the artifact name variable and related patterns
rg -A 2 'G_CLP_FFI_JS_DIST_ARTIFACT_NAME|artifact' .github/workflows/publish-to-npm.yml

Length of output: 540

@junhaoliao junhaoliao merged commit b3231bf into y-scope:main Dec 31, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants